package leetcode.每日一题;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：zsy
 * @date ：Created 2022/11/23 7:54 PM
 * @description：
 */
public class 盒子中小球的最大数量 {
    @Test
    public void test() {

    }

    /**
     *          1 2 3 4 5 6 7 8 9 10 11 ...
     * 小球数量：2 1 1 1 1 1 1 1 1 0 0 ...
     */
    class Solution {
        public int countBalls(int lowLimit, int highLimit) {
            Map<Integer, Integer> map = new HashMap<>();
            int res = 0;
            for (int i = lowLimit; i <= highLimit ; i++) {
                int box = 0;
                int x = i;
                while (x != 0) {
                    box += x % 10;
                    x /= 10;
                }
                map.put(box, map.getOrDefault(box, 0) + 1);
                res = Math.max(res, map.get(box));
            }
            return res;
        }
    }
}
